package com.qf.JDBC2;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wangyu
 * @Classname: TestORM
 * @Description: TEST
 * @date 2022-04-04 15:58
 */
public class TestORM {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        List<T_jobs> t_jobsList = new ArrayList<>();

        try {
            connection = DBUtitls.getConnection();
            preparedStatement = connection.prepareStatement("select * from user");
            resultSet = preparedStatement.executeQuery();

            while (resultSet.next()){
                String id = resultSet.getString("id");
                String userName = resultSet.getString("userName");
                String userpassword = resultSet.getString("userpassword");
                String number = resultSet.getString("number");
//                创建对象封装获取到的数据
                T_jobs t_jobs = new T_jobs();
                t_jobs.setId(id);
                t_jobs.setUserName(userName);
                t_jobs.setUserpassword(userpassword);
                t_jobs.setNumber(number);
//                System.out.println(t_jobs);
//                每遍历一次得到对象，存放在集合里，方便后续的使用
                t_jobsList.add(t_jobs);
            }
            for (T_jobs t : t_jobsList) {
                System.out.println(t);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtitls.closeAll(connection,preparedStatement,resultSet);
        }

    }
}
